package dao.impl;

import bean.Referee;
import dao.RefereeDao;
import util.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Auther leiHua
 * @Date 2022/5/8
 */
public class RefereeDaoImpl implements RefereeDao {
    @Override
    public Referee select(String name) {
        Connection conn=null;
        PreparedStatement ps =null;
        ResultSet rs =null;
        Referee referee = new Referee();
        try {
            conn= JdbcUtils.getConnection();
            ps=conn.prepareStatement("select * from referee where name=?");
            ps.setString(1,name);
            rs=ps.executeQuery();
            if (rs.next()){
                String id=rs.getString(1);
                String sex=rs.getString(3);
                int age = rs.getInt(4);
                referee.setR_id(id);
                referee.setName(name);
                referee.setAge(age);
                referee.setSex(sex);

            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.close(conn,ps,rs);
        }
        return referee;
    }
}
